package com.imufe.chemicalenterprisedangerwarning.controller;

import com.imufe.chemicalenterprisedangerwarning.entity.query.CreateGroup;
import com.imufe.chemicalenterprisedangerwarning.entity.query.EnterpriseDepartmentQuery;
import com.imufe.chemicalenterprisedangerwarning.entity.query.UpdateGroup;
import com.imufe.chemicalenterprisedangerwarning.entity.vo.EnterpriseDepartmentVO;
import com.imufe.chemicalenterprisedangerwarning.service.EnterpriseDepartmentService;
import com.imufe.chemicalenterprisedangerwarning.common.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 企业部门表 前端控制器
 * </p>
 *
 * @author BaiBan
 * @since 2022-09-24
 */
@Api(tags = "企业人员信息")
@RestController
@RequestMapping("/enterprise-department")
public class EnterpriseDepartmentController {

    @Autowired
    EnterpriseDepartmentService service;

    // 增删改
    @ApiOperation(value = "新增", notes = "新增一个企业部门，返回新增的企业部门")
    @PostMapping("/create")
    public ResponseEntity<EnterpriseDepartmentVO> create(@RequestBody @Validated(CreateGroup.class) EnterpriseDepartmentQuery query) {
        EnterpriseDepartmentVO vo = service.create(query);
        return ResponseEntity.success(vo);
    }

    @ApiOperation(value = "删除", notes = "删除一个企业部门")
    @DeleteMapping("/delete")
    public ResponseEntity<?> delete(Long id) {
        service.removeById(id);
        return ResponseEntity.success();
    }

    @ApiOperation(value = "修改", notes = "修改一个企业部门，返回修改后的企业部门信息")
    @PutMapping("/update")
    public ResponseEntity<EnterpriseDepartmentVO> update(@RequestBody @Validated(UpdateGroup.class) EnterpriseDepartmentQuery query) {
        EnterpriseDepartmentVO vo = service.update(query);
        return ResponseEntity.success(vo);
    }
}
